/**
 * 埋点类
 * 新建一个埋点实例，负责执行某个行为的埋点
 */
import { buried } from "@/api/common";
const defaultOptions = {
  oneceTime: true, // 是否只执行一次
  enterType: "", // 埋点参数
};

class EventTracking {
  constructor(options = {}) {
    this.options = {
      ...defaultOptions,
      ...options,
    };
    this.times = 0;
  }
  // 发送埋点
  async send() {
    if (this.options.oneceTime && this.times === 1) {
      return;
    }
    return buried({ type: this.options.enterType }).then((res) => {
      this.times++;
      return res;
    });
  }
}

export default EventTracking;
